<?php

namespace App\Models\Vuls;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class VulsCount extends Model
{
    //关联表
    protected  $table = 'vuls_count';
    /**生成漏洞编码
     * @return string
     */
    public static function creatVulsCode()
    {
        $year = date('Y');
        $find = VulsCount::where('year', $year)->first();
        $years = self::selectYear($year);
        if (empty($find)) {
            $code = "HVE-" . $years . '-00001';
        } else {
            $count = $find->count;
            $count += 1;
            $num = str_pad($count, 5, 0, STR_PAD_LEFT);
            $code = "HVE-" . $years . '-' . $num;
        }
        return $code;

    }
    /**
     * selectYear 设置年份
     *
     * @param $year
     * @return string
     */
    public static function selectYear($year)
    {
        $result = strpos($year, "0", 0);
        if ($result) {
            $result = $result + 1;
        }
        $years = substr($year, $result);
        return $years;
    }
}
